home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
351-375
/
disk_360
/
uucp
/
uucp0.lzh
/
src
/
anews
/
raw.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-17
|
3KB
|
142 lines
#if defined(LATTICE) || defined(_DCC)
/*
* Routines specific to Lattice C.
*/
/*
* raw.c
*
* This is a routine for setting a given stream to raw or cooked mode on the
* Amiga. This is useful when you are using Lattice C to produce programs
* that want to read single characters with the "getch()" or "fgetc" call.
*
* Written : 18-Jun-87 By Chuck McManis.
*/
#include <exec/types.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#ifdef LATTICE
#include <ios1.h>
#endif
#include <errno.h>
#include <stdio.h>
/*
* Function raw() - Convert the specified file pointer to 'raw' mode. This
* only works on TTYs and essentially keeps DOS from translating keys for
* you, also (BIG WIN) it means getch() will return immediately rather than
* wait for a return. You lose editing features though.
*/
long
raw(fp)
FILE *fp;
{
struct MsgPort *mp; /* The File Handle message port */
struct FileHandle *afh;
long Arg[1], res;
#ifdef LATTICE
{
struct UFB *ufb;
ufb = (struct UFB *) chkufb(fileno(fp)); /* Step one, get the file */
afh = (struct FileHandle *) (ufb->ufbfh);
}
#else
afh = (struct FileHandle *)fdtofh(fileno(fp));
#endif
if (!IsInteractive(afh)) { /* Step two, check to see if it's a console */
errno = ENOTTY;
return (-1);
}
/* Step three, get it's message port. */
mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
Arg[0] = -1L;
res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1); /* Put it in RAW: mode */
if (res == 0) {
errno = ENXIO;
return (-1);
}
return (0);
}
/*
* Function - cooked() this function returns the designate file pointer to
* its normal, wait for a <CR> mode. This is exactly like raw() except that
* it sends a 0 to the console to make it back into a CON: from a RAW:
*/
long
cooked(fp)
FILE *fp;
{
struct MsgPort *mp; /* The File Handle message port */
struct FileHandle *afh;
long Arg[1], res;
#ifdef LATTICE
{
struct UFB *ufb;
ufb = (struct UFB *) chkufb(fileno(fp));
afh = (struct FileHandle *) (ufb->ufbfh);
}
#else
afh = (struct FileHandle *)fdtofh(fileno(fp));
#endif
if (!IsInteractive(afh)) {
errno = ENOTTY;
return (-1);
}
mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
Arg[0] = 0;
res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1);
if (res == 0) {
errno = ENXIO;
return (-1);
}
return (0);
}
#else /* ---------------------------------------------- */
/*
* Routines specific to Aztec C.
*/
#include "news.h"
#include <sgtty.h>
#include <fcntl.h>
/*
* put the console into raw or cooked mode
*/
raw(FILE *f)
{
struct sgttyb ttyinfo;
if (ioctl(fileno(f), TIOCGETP, &ttyinfo) < 0) return -1;
ttyinfo.sg_flags |= RAW;
if (ioctl(fileno(f), TIOCSETP, &ttyinfo) < 0) return -1;
return 0;
}
cooked(FILE *f)
{
struct sgttyb ttyinfo;
if (ioctl(fileno(f), TIOCGETP, &ttyinfo) < 0) return -1;
ttyinfo.sg_flags &= ~RAW;
if (ioctl(fileno(f), TIOCSETP, &ttyinfo) < 0) return -1;
return 0;
}
#endif